package com.example.spring.demo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.spring.demo.common.error.CustomException;
import com.example.spring.demo.common.model.PageBean;
import com.example.spring.demo.common.model.req.GoodsOrderParam;
import com.example.spring.demo.common.model.req.MyGoodsParam;
import com.example.spring.demo.common.model.vo.GoodsOrderVo;
import com.example.spring.demo.entity.Goods;
import com.example.spring.demo.entity.GoodsOrder;
import com.example.spring.demo.service.GoodsOrderService;
import com.example.spring.demo.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2024/12/31 10:49
 **/
@RestController
@RequestMapping("/api/goodsOrder")
public class GoodsOrderController {
    @Autowired
    private GoodsOrderService goodsOrderService;

    @Autowired
    private GoodsService goodsService;
    //交易订单
    @PostMapping("/replaceOrder")
    public String replaceOrder(@RequestBody GoodsOrder order){
        goodsOrderService.replaceOrder(order);
        return "交易成功!";
    }

    //小程序我的订单
    @GetMapping("/getMyOrder")
    public IPage<Goods> getMyOrder(MyGoodsParam param){
        return goodsService.getMyOrder(param);
    }
    //我的出售订单
    @GetMapping("/getSellOrder")
    public IPage<Goods> getSellOrder(MyGoodsParam param){
        return goodsService.getSellOrder(param);
    }

    //删除订单
    @PostMapping("/deleteOrder")
    public String deleteOrder(@RequestBody GoodsOrder param){
        if(goodsOrderService.removeById(param.getOrderId())){
            return "删除成功!";
        }
        throw new CustomException("删除失败!");
    }

    //订单列表
    @GetMapping("/getList")
    public PageBean<GoodsOrderVo> getList(GoodsOrderParam param){
        return goodsOrderService.getPageList(param);
    }
}